/* eslint-disable no-unused-vars */
import AutoImport from 'unplugin-auto-import/vite';
import type { PluginOption } from 'vite';

import { GllComponentResolver, GllHooksResolver, GllStoresResolver } from './modules';
import { AntDesignVueResolver } from './unplugin-vue-components/core/resolvers/antdv';
import Components from './unplugin-vue-components/vite';

export function configAutoImport(): PluginOption[] {
  const plugins: PluginOption[] = [];

  // unplugin-auto-import/vite
  plugins.push(
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        'pinia',
        {
          '@gll/types': [
            'AnyFunction',
            'AnyNormalFunction',
            'AnyPromiseFunction',
            'IntervalHandle',
            'NonNullable',
            'Nullable',
            'ReadonlyRecordable',
            'Recordable',
            'TimeoutHandle',
          ],
        },
        {
          '@vueuse/core': [
            'onKeyStroke',
            'useDebounceFn',
            'onClickOutside',
            'tryOnUnmounted',
            'useTransition',
            'TransitionPresets',
            'useMutationObserver',
            'useFullscreen',
            'useThrottleFn',
            ['useTitle', 'usePageTitle'],
            'useWebSocket',
            'FunctionArgs',
          ],
        },
      ],

      eslintrc: {
        enabled: true, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
      //组件库中的api,比如：ElMessage.success()
      resolvers: [
        AntDesignVueResolver({ importStyle: false, resolveIcons: false }),
        GllStoresResolver(),
        GllHooksResolver(),
      ],

      //为true时在项目根目录自动创建
      dts: 'types/auto-imports.d.ts',
    }),
  );

  plugins.push(
    Components({
      dirs: [], //['src/components'],
      //自动导入antd
      resolvers: [
        AntDesignVueResolver({ importStyle: false, resolveIcons: true }),
        GllComponentResolver(),
      ],
      //组件名称包含目录，防止同名组件冲突
      // directoryAsNamespace: false,
      //指定类型声明文件，为true时在项目根目录创建
      dts: 'types/components.d.ts',
      //给src/components下的组件，统一添加g-xxxxx
      // prefixCompName: 'G',
      //忽略本地组件的路径转换
      // ignoreRelatedTransform: (path) => path.includes('/@/'),
      //不需要每次都重新生成同一组件
      allowOverrides: false,
    }),
  );

  return plugins;
}
